home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / GAP.TST / GAPTST.C < prev    next >
C/C++ Source or Header  |  1996-02-23  |  4KB  |  117 lines

  1. /* ============ */
  2. /* gaptst.c    */
  3. /* ============ */
  4. #include <math.h>
  5. #include <defcodes.h>
  6. #include <miscdefs.h>
  7. #include <gapdefs.h>
  8. #include <mconf.h>
  9.  
  10. #define    NUM_PROBS    100
  11.  
  12. static    GAP_DATA_STRU     GapData;
  13. static    INIT_DATA_STRU    InitialData;
  14. /* ==================================================================== */
  15. /* GapTest - Executes Gap Test per Knuth                */
  16. /* ==================================================================== */
  17. void
  18. main(void)
  19. {
  20.     int        k;
  21.     long    TotVariates = 0;
  22.     double  DegFree;
  23.     double  KnMinusProb, KnMinusStat, KnPlusProb, KnPlusStat;
  24.  
  25.     double  ChiSqProb[NUM_PROBS];
  26.  
  27.     AbortGracefully();            /* Make ^C act reasonably */
  28.  
  29.     printf("\t\tG A P  T E S T\n\n");
  30.     GetInitialData(&InitialData);
  31.     fprintf(stderr, "\n"); fflush(NULL);
  32.  
  33.     /* -------------------------- */
  34.     /* Print Initial Data Entries */
  35.     /* -------------------------- */
  36.     printf("Starting Seed = %u%s\n", InitialData.UserSeed,
  37.     (InitialData.SeedSrce == (UINT)(-1)) ?
  38.         " (Unsigned Integer Part of Time of Day)" : "");
  39.  
  40.     printf("Generator     = %s\n", InitialData.GenName);
  41.  
  42.     GapData.RandFun = InitialData.RandFun;
  43.     SetGapControls(&GapData);
  44.  
  45.     fflush(NULL);
  46.     if (!GapData.CallStatusOK)
  47.     {
  48.     printf("At Least One Category Has a Cell Expectation Less"
  49.         " Than Number Requested.\n");
  50.     printf("The number of deficient categories is %d\n",
  51.         GapData.NotEnough);
  52.     if (GapData.NumGaps < GapData.UserNumGaps)
  53.     {
  54.         P(printf("For the Inputs That You Have Provided At Least %ld"
  55.         " Gaps are Required.\n", GapData.UserNumGaps));
  56.     }
  57.     if (GapData.UserNumGaps > MAX_NUM_GAPS)
  58.     {
  59.         printf("This Number is Greater Than the Maximum Number "
  60.            "Allowed (%d).\nSuggest You Reduce Gap Boundaries, "
  61.            "Gap Length, Number of Gaps (or All Three).\n",
  62.            MAX_NUM_GAPS);
  63.     }
  64.     if (GapData.UserCellExpect != MIN_CELL_XPCT)
  65.     {
  66.         P(printf("For a Minimum of %d Samples Per Category At"
  67.         " Least %ld Gaps are Required.\n", MIN_CELL_XPCT,
  68.         GapData.IdealNumGaps));
  69.     }
  70.  
  71.     printf("Run plangap.exe to Determine Appropriate Number of"
  72.         " Gaps to be Counted.\n");
  73.     exit(1);
  74.     }
  75.  
  76.     DegFree = GapData.NumCategories - 1;
  77.  
  78.     /* ------------------------- */
  79.     /* Generate Random Numbers,  */
  80.     /* Calculate Chi-Square Data */
  81.     /* ------------------------- */
  82.     for (k = 0; k < NUM_PROBS; ++k)
  83.     {
  84.     CalcGapChiSq(&GapData);
  85.  
  86.     fprintf(stderr, "\rPass %3d (of %d), %8ld  Total Random Numbers",
  87.         k+1, NUM_PROBS, TotVariates += GapData.TotNumGen);
  88.  
  89.     ChiSqProb[k] = chdtr(DegFree, GapData.GapChiSq);
  90.  
  91.     if (ChiSqProb[k] < 0)
  92.     {
  93.         fprintf(stderr, "\nChiSqFreq(): Function chdtr() "
  94.         "Returned Negative Probability -  Can't Happen.\n");
  95.     }
  96.     }
  97.  
  98.     /* -------------------------------------------------------- */
  99.     /* Calculate K-S on Chi-Square Statistics and Probabilities */
  100.     /* -------------------------------------------------------- */
  101.     fflush(NULL);
  102.     KSCalc(ChiSqProb, NUM_PROBS,
  103.         &KnPlusStat, &KnPlusProb,
  104.          &KnMinusStat, &KnMinusProb);
  105.  
  106.    printf("\nKolmogorov-Smirnov Statistics and Probabilities"
  107.     " on Chi-Square Data\n");
  108.  
  109.    printf("\tK(%d)+ = %f (Knuth) or %9f%%\n", NUM_PROBS,
  110.     sqrt((double)NUM_PROBS)*KnPlusStat, 100*KnPlusProb);
  111.  
  112.    printf("\tK(%d)- = %f (Knuth) or %9f%%\n", NUM_PROBS,
  113.     sqrt((double)NUM_PROBS)*KnMinusStat, 100*KnMinusProb);
  114.  
  115.     printf("\nThis Run Required %ld Random Numbers\n\n", TotVariates);
  116. }
  117.